package com.nowcoder.community.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.io.File;

/**
 * @ClassName WkConfig
 * @Description
 * @Author hhwu
 * @Date 2022/6/1 21:55
 * Version 1.0
 **/
@Configuration// 加上这个注解后，项目启动时，spring会优先实例化该类
public class WkConfig {

    private static final Logger logger = LoggerFactory.getLogger(WkConfig.class);

    @Value("${wk.image.storage}")
    private String wkImageStorage;
    @Value("${wk.pdf.storage}")
    private String wkPdfStorage;

    @PostConstruct
    public void init() {
        // 创建WK图片目录
        File file = new File(wkImageStorage);
        if (!file.exists()) {
            file.mkdir();
            logger.info("创建WK图片目录: " + wkImageStorage);
        }

        // 创建WKpdf目录
        file = new File(wkPdfStorage);
        if (!file.exists()) {
            file.mkdir();
            logger.info("创建WK的pdf目录: " + wkPdfStorage);
        }
    }
}
